package cn.bsuc.crm.util;

import lombok.Data;

@Data
public class Result<T> {

    private Integer code; //状态码
    private String msg; //返回的文字提示信息
    private T data; //返回的数据
    private String token;


    private Result(Integer code, T data, String msg) {
        this.code = code;
        this.data = data;
        this.msg = msg;
    }

    private Result(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    private Result(Integer code, T data, String msg, String token) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.token = token;
    }
//对外提供几个static方法，创建该对象

    public static Result ok() {
        return new Result(Code.OK, "success");
    }

    public static <T> Result<T> ok(T t) {
        return new Result(Code.OK, t, "success");
    }

    public static <T> Result<T> ok(T t, String msg) {
        return new Result(Code.OK, t, msg);
    }

    // 自定义成功 状态码 返回数据 返回信息
    public static <T> Result<T> ok(Integer code, T t, String msg) {
        return new Result(code, t, msg);
    }
    // 自定义成功 状态码 返回数据 返回信息 token
    public static <T> Result<T> ok(Integer code, T t, String msg, String token) {
        return new Result(code, t, msg, token);
    }


    //失败 系统
    public static Result failSys() {
        return new Result(Code.SYSTEM_ERR, "服务器内部出错，请稍后再试");
    }

    // 自定义失败 状态码 返回信息
    public static Result fail(Integer code, String msg) {
        return new Result(code, msg);
    }

}
